<?php
namespace app\controller;
use app\BaseController;
use app\model\Admin;
use think\facade\View;
use think\response\Json;

class PassPort extends BaseController {
	/**
	 * 登录控制
	 * @return array|Json|View
	 */
	public function login() {
		
	 	if ($this->request->isAjax ()) {
			$model = new Admin ();
			// if ($model->login ( $this->postData ( 'User' ) )) {
				
			// 	return $this->renderSuccess ( '登录成功', url ( '/index/index' ) );
			// }
			if ($model->login(['name'=>$this->request->post('name'),'password'=>$this->request->post('password')])) {
				return $this->renderSuccess ( '登录成功', url ( '/index/home' ) );
			}
			return $this->renderError ( '用户名或密码错误',url ('/index/login') );
		}
		//return view ( 'login' );
	}
	
	//开发用，添加管理员
	public function addAdmin(){
		$model = new Admin ();
		$model->save([
			'name'=>'admin',
			'password'=>salt_hash('admin'),
			'wxapp_id'=>'10001'
		]);
				
	}
}